<%@ taglib uri="/WEB-INF/struts-bean" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic" prefix="logic" %>

<table class="tbForm">
	<tr>
		<th colspan="2" align="center"><bean:message key="formulario.compra" /></th>
	</tr>
	<tr>
		<td align="right" width="50%"><bean:message key="formulario.compra.datacompra" />: </td>
		<td align="left" width="50%"><bean:write name="compra" property="dataCompra" formatKey="sistema.padrao.data"/></td>
	</tr>
	<tr>
		<td align="right"><bean:message key="formulario.compra.numeronotafiscal" />: </td>
		<td align="left"><bean:write name="compra" property="numeroNotaFiscal" /></td>
	</tr>
	<logic:equal name="compra" property="finalizada" value="false">
	<tr>
		<td>&nbsp;</td>
		<td align="right">
			<html:form action="/sistema/compra/finalizar">
				<html:hidden name="compra" property="compraId"/>
				<html:submit>
					<bean:message key="formulario.compra.finalizar"/>
				</html:submit>
				<html:img pageKey="sistema.ico.dica" onclick="abrirJanelaDica('compra/finalizar.htm')" />
			</html:form>
		</td>
	</tr>
	</logic:equal>
</table>
<br>

<table class="tbForm">
	<tr>
		<th colspan="6" align="center"><bean:message key="formulario.compra.itens" /></th>
	</tr>
	<tr>
		<th width="35%" align="center"><bean:message key="formulario.itemcompra.materiaprima" /></th>
		<th width="05%" align="center"><bean:message key="formulario.materiaprima.unidade" /></th>
		<th width="10%" align="center"><bean:message key="formulario.itemcompra.quantidade" /></th>
		<th width="20%" align="center"><bean:message key="formulario.itemcompra.precounitario" /></th>
		<th width="20%" align="center"><bean:message key="formulario.itemcompra.precototal" /></th>
		<th width="10%" align="center">&nbsp;<html:img pageKey="sistema.ico.dica" onclick="abrirJanelaDica('compra/item/materiaprima.htm')" /></th>
	</tr>
	<logic:iterate id="item" name="compra" property="itensCompra">
		<html:form action="/sistema/compra/item/remover" method="post">
			<tr>
				<td align="left"><bean:write name="item" property="materiaPrima.nome" /></td>
				<td align="center"><bean:write name="item" property="materiaPrima.unidade" /></td>
				<td align="right"><bean:write name="item" property="quantidade" /></td>
				<td align="right"><bean:write name="item" property="precoUnitario" /></td>
				<td align="right">${item.quantidade * item.precoUnitario}</td>
				<td align="center">
					<bean:define id="materiaPrima" name="item" property="materiaPrima" />
					<html:hidden name="materiaPrima" property="materiaPrimaId" />
					<html:hidden name="compra" property="compraId" />
					<html:submit onclick="return confirmaRemocao()"><bean:message key="sistema.botao.remover" /></html:submit>
				</td>
			</tr>
			<tr><td height="1" bgcolor="#EEEEEE" colspan="6"></td></tr>
		</html:form>
	</logic:iterate>
	<tr>
		<th align="right" colspan="4"><bean:message key="formulario.compra.total"/></th>
		<th align="right"><bean:write name="compra" property="totalCompra"/></th>
		<th>&nbsp;</th>
	</tr>
	<logic:empty name="compra" property="itensCompra">
		<!-- lista vazia -->
	</logic:empty>
</table>
<br>
<br>
<html:form action="/sistema/compra/item/adicionar" method="post">
	<table class="tbForm">
		<tr><th colspan="2" align="center"><bean:message key="formulario.compra.itens.adicionar" /></th></tr>
		<tr>
			<td align="right" width="40%"><bean:message key="formulario.materiaprima.nome" />:</td>
			<td>
				<html:select property="materiaPrimaId">
					<html:option value="" />
					<html:options collection="materiasPrimas" labelProperty="nomeItemComboBox" property="materiaPrimaId" />
				</html:select>
				<html:img pageKey="sistema.ico.dica" onclick="abrirJanelaDica('compra/item/selecionar-materiaprima.htm')" />
				<logic:messagesPresent message="false">
					<html:messages id="mensagem" message="false" property="materiaPrimaId">
						<br><span class="erro"><bean:write name="mensagem" /></span>
					</html:messages>
				</logic:messagesPresent>
			</td>
		</tr>
		<tr>
			<td align="right"><bean:message key="formulario.itemcompra.quantidade" />:</td>
			<td>
				<html:text property="quantidade" size="10" maxlength="8" />
				<html:img pageKey="sistema.ico.dica" onclick="abrirJanelaDica('compra/item/informar-quantidade.htm')" />
				<logic:messagesPresent message="false">
					<html:messages id="mensagem" message="false" property="quantidade">
						<br><span class="erro"><bean:write name="mensagem" /></span>
					</html:messages>
				</logic:messagesPresent>
			</td>
		</tr>
		<tr>
			<td align="right"><bean:message key="formulario.itemcompra.precounitario" />:</td>
			<td>
				<html:text property="precoUnitario" size="10" maxlength="8" />
				<html:img pageKey="sistema.ico.dica" onclick="abrirJanelaDica('compra/item/informar-precounitario.htm')" />
				<logic:messagesPresent message="false">
					<html:messages id="mensagem" message="false" property="precoUnitario">
						<br><span class="erro"><bean:write name="mensagem" /></span>
					</html:messages>
				</logic:messagesPresent>
			</td>
		</tr>
		<tr>
			<td></td>
			<td align="left">
				<html:submit><bean:message key="sistema.botao.compra.item.adicionar" /></html:submit>
				<html:hidden name="compra" property="compraId" />
			</td>
		</tr>
	</table>
</html:form>